package net.elswear;

import java.io.IOException;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.*;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class IndexServlet extends HttpServlet 
{
	private static final Logger log = Logger.getLogger(IndexServlet.class.getName());
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			Page p = pm.getObjectById(Page.class, "Index");
			
			if (p.getName().equalsIgnoreCase("Index"))
			{						
				request.setAttribute("title", p.getTitle());
				request.setAttribute("content", p.getContent());
			}
			else 
			{
				request.setAttribute("title", null);
				request.setAttribute("content", null);
			}
		}
		finally
		{
			pm.close();
		}

		RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
		dispatcher.forward(request, response);
	}
}
